package com.example.vo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import static com.example.utils.SystemConstants.RESPONSE_GENERAL_ERR;
import static com.example.utils.SystemConstants.RESPONSE_OK;

/**
 * 将相应对象封装结果集
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Result {

    // 是否成功
    private boolean success;

    // 响应状态码
    private int statusCode;

    // 错误信息
    private String errMessage;

    // 响应的数据
    private Object data;

    public static Result success() {
        return new Result(true, RESPONSE_OK, null, null);
    }

    public static Result success(Object data) {
        return new Result(true, RESPONSE_OK, null, data);
    }

    public static Result error(String errorMsg, Integer statusCode) {
        return new Result(false, statusCode, errorMsg, null);
    }

    public static Result error(String errorMsg) {
        return new Result(false, RESPONSE_GENERAL_ERR, errorMsg, null);
    }
}
